package com.briup.day21;

public class Test_DeadLock {
    public static void main(String[] args) {
        Object obj1 = new Object();
        Object obj2 = new Object();
        Thread t1=new Thread(){
            public void run(){
                    for (int i = 0; i < 100; i++) {
                        synchronized (obj1){
                            System.out.println("t1拿到了左筷子");
                           synchronized (obj2){
                               System.out.println("t1拿到了右筷子");
                               System.out.println("t1吃到了水煮羊");
                           }
                        }
                    }
            }
        };
        Thread t2=new Thread(){
            public void run(){
                    for (int i = 0; i < 100; i++) {
                        synchronized (obj2){
                            System.out.println("t2拿到了左筷子");
                           synchronized (obj1){
                               System.out.println("t2拿到了右筷子");
                               System.out.println("t2吃到了饭");
                           }
                        }
                    }
            }
        };
        t1.start();

        t2.start();
    }
}
